package com.colorful.insuranceproject.dialog;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.colorful.insuranceproject.R;
import com.colorful.insuranceproject.base.CommonDialogFragment;
import com.lovely3x.common.utils.ViewUtils;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lovely3x on 17/3/2.
 *
 *   推出的布局
 */
public class QuitAlertDialog extends CommonDialogFragment {

    public static QuitAlertDialog newInstance() {

        Bundle args = new Bundle();

        QuitAlertDialog fragment = new QuitAlertDialog();
        fragment.setArguments(args);
        return fragment;
    }

    private CallBack mCallBack;

    @Override
    protected int getContentView() {
        return R.layout.view_exit_app;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this, mRootView);
    }

    @Override
    protected void onViewInitialized() {

    }

    @OnClick(R.id.cancel)
    public void onCancelClicked() {
        if (mCallBack != null && mCallBack.onCancelClicked()) {
            return;
        }
        dismissAllowingStateLoss();
    }

    @OnClick(R.id.sure)
    public void onSureClicked() {
        if (mCallBack != null && mCallBack.onSureClicked()) {
            return;
        }
        dismissAllowingStateLoss();
    }

    public void setCallBack(CallBack callBack) {
        mCallBack = callBack;
    }

    @Override
    protected void setupWindowAttrs(Window window) {

        if (window != null) {
            WindowManager.LayoutParams lp = window.getAttributes();

            Rect displayRectangle = new Rect();
            window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);

            lp.gravity = Gravity.CENTER;

            lp.width = Math.min(displayRectangle.width(), ViewUtils.dp2pxF(300));
            lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;

            window.setAttributes(lp);
        }
    }

    public interface CallBack {

        boolean onSureClicked();

        boolean onCancelClicked();
    }
}
